package org.nox.helloseries.rest;

import javax.inject.Named;

import restx.factory.Module;
import restx.factory.Provides;
import restx.mongo.MongoModule;
import restx.security.CORSAuthorizer;
import restx.security.SignatureKey;
import restx.security.StdCORSAuthorizer;

import com.google.common.base.Charsets;
import com.google.common.base.Optional;
import com.google.common.base.Predicates;
import com.google.common.collect.ImmutableList;

@Module
public class AppModule
{
    @Provides
    public CORSAuthorizer cors()
    {
        return StdCORSAuthorizer.builder().setOriginMatcher( Predicates.<CharSequence> alwaysTrue() ).setPathMatcher( Predicates.<CharSequence> alwaysTrue() )
            .setAllowedMethods( ImmutableList.of( "GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS" ) )
            .setAllowedHeaders( ImmutableList.of( "Origin", "X-Requested-With", "Content-Type", "Accept", "User-Agent" ) ).setAllowCredentials( Optional.of( Boolean.TRUE ) ).build();
    }

    @Provides
    public SignatureKey signatureKey()
    {
        return new SignatureKey( "3685755889849339038 636b37d4-f945-4a6b-8fea-31900e12861a helloseries-rest helloseries-rest".getBytes( Charsets.UTF_8 ) );
    }

    @Provides
    @Named( MongoModule.MONGO_DB_NAME )
    public String dbName()
    {
        return "helloseries-mongodb";
    }
}